<?php

use App\Enums\RefundState;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('refunds', function (Blueprint $table) {
            $table->id();
            $table->application();
            $table->string('no', 32)
                ->unique()
                ->comment('单据编号');
            $table->unsignedBigInteger('order_id')
                ->index();
            $table->decimal('amount');
            $table->enum('state', RefundState::values());
            $table->json('resource')
                ->nullable();
            $table->dateTime('refunded_at')
                ->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('refunds');
    }
};
